<!doctype html>
<html>
<head>
<meta charset="utf-8">
    <title>收货地址</title>
    <meta content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0" name="viewport">     
    <meta content="yes" name="apple-mobile-web-app-capable">     
    <meta content="black" name="apple-mobile-web-app-status-bar-style">     
    <meta content="telephone=no" name="format-detection">
    <link rel="shortcut icon" href="/favicon.ico">
    <link rel="stylesheet" type="text/css" href="/H5/css/sm.min.css" />
    <link rel="stylesheet" type="text/css" href="/H5/css/reset.css" />
    <link rel="stylesheet" type="text/css" href="/H5/css/order.css?v=10" />
</head>             
<body>
    <div class="page-group ms-controller" :controller="addressList">
        <div class="page page-current">
            <header class="bar bar-nav">
                <a class="icon icon-left pull-left" href="javascript:window.history.go(-1)"></a>
                <a class="icon icon-home pull-right" href="/H5"></a>
                <h1 class="title">收货地址</h1>
            </header>
            <div class="content visibility">
                <div class="address_main" :for="el in @data">
                    <a :on-click="@jump(el.id)" class='address_first' :if="el.is_default==1">
                        <div class="address_text">{{el.name||""}}<span>{{el.mobile_secure||""}}</span><b>默认</b></div>
                        <div class="address_add">{{el.area_label+" "+el.address}}</div>
                    </a>
                    <a :on-click="@jump(el.id)" class='address_first' :if="el.is_default==0">
                        <div class="address_text">{{el.name||""}}<span>{{el.mobile_secure||""}}</span></div>
                        <div class="address_add">{{el.area_label+" "+el.address}}</div>
                    </a>
                </div>
                <button :on-click="@addnew" class="address_btn">+添加新地址</button>
            </div>
        </div>
    </div>
    <script type='text/javascript' src='/H5/js/zepto.min.js' charset='utf-8'></script>
    <script type='text/javascript' src='/H5/js/sm.min.js' charset='utf-8'></script>
    <script type='text/javascript' src='/H5/js/avalon.js' charset='utf-8'></script>
    <script type='text/javascript' src='/H5/js/simpleStorage.js' charset='utf-8'></script>
    <script type='text/javascript' src='/H5/js/mall.js' charset='utf-8'></script>
    <script>
        var addressList = avalon.define({
            $id: "addressList",
            data: {},
            params: Mall.parseUrl(window.location.href),
            getAddress: function(){
                Mall.request("/api/AddressList")
                    .always( function( data ){
                        if( data.error_code == 0 ){
                            addressList.data = data.data;
                            $( ".content" ).removeClass( "visibility" )
                        }
                        else{
                            $.alert(data.error_msg);
                        }
                    } )
            },
            addnew: function(){
                window.location.href = "/H5/newaddress";
            },
            jump: function( id ){
                if( addressList.params.id ){
                    var url = window.location.href.replace( "addresslist", "cart" );
                    url = url + "&addressId="+id;
                    window.location.href = url;
                }
                else{
                    window.location.href = "/H5/address?addressId="+id;
                }
            }
        })
        addressList.getAddress();
        avalon.scan( document.body );
    </script>
</body>
</html>
